package com.xywang;

import com.xywang.dao.user.UserDao;
import com.xywang.pojo.Bill;
import com.xywang.pojo.Provider;
import com.xywang.pojo.User;
import com.xywang.service.bill.BillService;
import com.xywang.service.provider.ProviderService;
import com.xywang.service.user.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class Testa {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-dao.xml");
        UserDao userDaoImpl = context.getBean("userDaoImpl", UserDao.class);
        User userById = userDaoImpl.getUserById(99);
        User admin = userDaoImpl.getLoginUser("admin");
        int userCount = userDaoImpl.getUserCount("系统", 1);
        List<User> list = userDaoImpl.getUserList(null, 2, 1, 5);
        for (User user : list) {
            System.out.println(user.toString());
        }
        System.out.println(userCount);
        System.out.println(admin);
        System.out.println(userById);
    }
    @Test
    public void test(){
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-dao.xml");
        UserDao userDaoImpl = context.getBean("userDaoImpl", UserDao.class);
        User user1 = new User();
        user1.setId(99);
        userDaoImpl.addUserDao(user1);
        User userById = userDaoImpl.getUserById(24);
        System.out.println(userById);
    }
    @Test
    public void test2(){
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-dao.xml");
        UserDao userDaoImpl = context.getBean("userDaoImpl", UserDao.class);
        int i = userDaoImpl.deleteUser(24);
        System.out.println(i);
    }
    @Test
    public void test3(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = context.getBean("userServiceImpl", UserService.class);
        User userByIdService = userService.getUserByIdService(2);
        System.out.println(userByIdService);
    }
    @Test
    public void test4(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = context.getBean("userServiceImpl", UserService.class);
        List<User> userList = userService.getUserList(null, 1, 1, 5);
        for (User user : userList) {
            System.out.println(user);
        }
    }
    @Test
    public void test5(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = context.getBean("userServiceImpl", UserService.class);
        User user = userService.getUserByIdService(2);
        System.out.println(user);
        user.setUserName("helloworld");
        userService.updateUserService(user);
        System.out.println(user);

    }
    @Test
    public void test6(){
        String birthday="Tue Nov 09 00:00:00 CST 2021";
        try {
            Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(birthday);
            String s = parse.toString();
            System.out.println(s);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void test7(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ProviderService billService = context.getBean("providerServiceImpl", ProviderService.class);
        List<Provider> providerListService = billService.getProviderListService("", "");
        for (Provider provider : providerListService) {
            System.out.println(provider);
        }
    }
    @Test
    public void test8(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ProviderService billService = context.getBean("providerServiceImpl", ProviderService.class);
        List<Provider> providerListService = billService.getProviderListService("", "");
        for (Provider provider : providerListService) {
            System.out.println(provider);
        }
    }
}
